﻿using System;
using System.Collections.Generic;

namespace JTLeigh.Commerce.Spencer.Features.ProductFeedback.Business
{

	/// <summary>
	/// Counter used to calculate the breakdown and average of a series of values.
	/// </summary>
	public class BreakdownAveragingCounter : AveragingCounter
	{

		#region Fields

		private Dictionary<byte, int> _breakdown;

		#endregion // Fields

		#region Constructors

		/// <summary>
		/// Initializes a new instance of the <see cref="BreakdownAveragingCounter"/> class.
		/// </summary>
		public BreakdownAveragingCounter()
		{
			_breakdown = new Dictionary<byte, int>();
		}

		#endregion // Constructors

		#region Properties

		/// <summary>
		/// Gets the breakdown of the values that have been added.
		/// </summary>
		/// <value>A <see cref="Dictionary{TKey, TValue}"/> containing the counts of each value 
		/// that have been added, keyed by the value.</value>
		public Dictionary<byte, int> Breakdown
		{
			get { return _breakdown; }
		}

		#endregion // Properties

		#region Methods

		/// <summary>
		/// Adds a value.
		/// </summary>
		/// <param name="value">The <see cref="Byte"/> value to add.</param>
		public override void AddValue(byte value)
		{
			base.AddValue(value);
			if (!_breakdown.ContainsKey(value))
			{
				_breakdown.Add(value, 0);
			}
			_breakdown[value]++;
		}

		/// <summary>
		/// Resets the counter.
		/// </summary>
		public override void Reset()
		{
			base.Reset();
			_breakdown.Clear();
		}

		#endregion // Methods

	}
}
